﻿//插件包 1.4.1
/*
2015-01-19 1.4.1
1.jselect中加入input,新增属性name为其设置name,可用于form提交

2014-12-26 1.4.0
1.新增数字滚动插件jnumroll

2014-12-09 1.3.0
1.新增下拉列表插件jselect

2014-09-04 1.2.5
1.调整了jbox关闭方法jbox_close的调用方式 $.jbox_close()
*保留了原来的调用方法 $().jbox.close()

2014-09-02 1.2.4
1.jbox实现adaptive参数的自适应高度功能
①配有top参数自行设置窗口位置
②在adaptive为true的情况下自定义进入效果无效

2014-08-23 1.2.3
1.jbox增加了关闭按钮,用closebtn参数进行配置;
2.jbox中修正了浏览器窗口改变大小时弹出层定位的问题;
3.新增调用方法isCss3来判断浏览器是否支持css3

2014-08-22 1.2.2
1.jbrowse中增加了放大缩小功能,需要jquery.mousewheel.js支持

2014-08-15 1.2.1
1.jbox中修正了多个对象调用时不同配置导致的配置覆盖的问题;
2.jbrowse中修正了因为图片高度过高导致的一些列bug

2014-08-14 1.2.0
1.新增图片浏览插件jbrowse;
2.新增调用方法isInclude来判断是否已经导入js或css文件;
3.新增结构/jPackageCss/jPackage.css和/jPackageImg/*.png,两个文件夹放在jPackage.js同一级目录

2014-08-13 1.1.3
1.jbox增加关闭方法,$().jbox_close()

2014-08-08 1.1.2
bug:多个调用时,如果参数配置不一样,会被最后一个调用的覆盖
1.jbox新增参数icss,可以在最内部的窗口自定义CSS属性,传入一个数组;
2.jbox新增参数paracut删除属性里的字符串,如果字符串里带有类似"url"等不必要字符串可以用这剔除;
3.jbox调整了para参数传入的方式,不是有para拼接"data-",而是传入完整的属性

2014-08-07 1.1.1
1.jbox新增传入参数nowt,使调用jbox时弹出窗口;
2.jbox新增参数adaptive,自适应内部内容的高宽

2014-08-07 1.1.0
1.新增抖动插件jshake

2014-08-06 1.0.2
1.jbox中修正了多个对象同时调用时弹出多个窗口的问题;
2.jbox新增参数effect,窗口进入时的效果以及不同位置的滑入;
3.jbox新增参数s_effect,背景出现效果;
4.jbox新增参数para,"data-"+para为一个属性写入被调用的对象中,指示内容载入的url或者其他元素的内容(#id或.class)
*/
//图片自动滚动,图片放大,弹出窗,抖动,图片浏览
(function ($) {
    $.fn.isInclude = function (name) {//判断是否已经导入js或css文件
        var js = /js$/i.test(name);
        var es = document.getElementsByTagName(js ? 'script' : 'link');
        for (var i = 0; i < es.length; i++)
            if (es[i][js ? 'src' : 'href'].indexOf(name) != -1) return true;
        return false;
    };
    $.fn.isCss3 = function () {//判断浏览器是否支持css3
        var div = document.createElement('div'), vendors = 'Khtml O Moz Webkit'.split(' '), len = vendors.length;
        prop = 'textShadow';
        if (prop in div.style) return true;
        if ('-ms-' + prop in div.style) return true;
        prop = prop.replace(/^[a-z]/, function (val) { return val.toUpperCase(); });
        while (len--) { if (vendors[len] + prop in div.style) { return true; } }
        return false;
    };
    $.jbox_close = function () {//弹出窗(点击窗口以外区域或者按ESC键关闭窗口,没有关闭按钮)
        $("[id*='jbox-']").remove();
    };
    $.fn.extend({
        /////
        jslide: function (con, fun) {//如果传入一个回调函数,参数为 图片的index
            var $container = $(this),
            option = {
                type: "slide", //切换类型:slide滑动,focus淡隐淡出
                interval: null, //图片自动切换时间间隔
                animateTime: 500, //图片切换动画速度
                direction: false, //切换方向,true切换到上一张图片,false切换到下一章图片
                selector: "li", //选择器
                leftBtn: null, //左按钮jQuery对象
                rightBtn: null, //右按钮jQuery对象
                list: null, //图片列表jQuery对象
                listDire: "horizontal", //列表横向(horizontal)或纵向(vertical)滚动
                listSel: "li", //图片列表中需要点击选择的图片选择器
                listNum: 5, //列表每一页图片数量
                listWidth: 860, //列表宽度/高度
                prevBtn: null, //列表左按钮jQuery对象
                nextBtn: null, //列表右按钮jQuery对象
                selClass: "", //列表选中样式
                message: null, //需要切换的文字
                tabSel: null, //焦点图片按钮选择器
                tabEvent: "hover", //焦点图片按钮触发事件
                tabClass: null //焦点图片按钮选中样式
            },
            config = $.extend(option, con),
            $imgs = $container.find(config.selector),
            imgLen = $imgs.length,
            width = $imgs.width(),
            i = 0,
            o = 0,
            funT = !0,
            listPage = (config.list !== null && config.list !== undefined) ? Math.ceil(config.list.find(config.listSel).length / config.listNum) : null,
            index = 0,
            getNextIndex = function (y) { return i + y >= imgLen ? 0 : i + y; },
            getPrevIndex = function (y) { return i - y < 0 ? imgLen - 1 : i - y; },
            call = {
                slide: function (d, k) {
                    funT = !0,
                    i = typeof (k) == "number" ? k : (d ? getPrevIndex(1) : getNextIndex(1));
                    $imgs.css("float") === "none" ? ($imgs.hide().eq(i).css("margin-left", (d ? -width : width)).add($imgs.eq(o)).show()
                    .animate({ "margin-left": (d ? "+" : "-") + "=" + width }, config.animateTime, function () { if (funT) { o = i; typeof (con) === "function" ? con(i) : fun && fun(i); funT = !1; } }))
                    : ($imgs.parent().animate({ "margin-left": i * -width }, config.animateTime, function () { typeof (con) === "function" ? con(i) : fun && fun(i); }));
                    tab(), listrun(), msgrun();
                },
                focus: function (d, k) {
                    i = typeof (k) == "number" ? k : (d ? getPrevIndex(1) : getNextIndex(1));
                    $imgs.fadeOut().eq(i).fadeIn(config.animateTime, function () { typeof (con) === "function" ? con(i) : fun && fun(i) });
                    tab(), listrun(), msgrun();
                }
            },
            flip = function () {
                config.listDire === "horizontal" ? config.list.animate({ left: -config.listWidth * index }, config.animateTime) : config.list.animate({ top: -config.listWidth * index }, config.animateTime)
            },
            listrun = function () {
                if (config.list !== null && config.list !== undefined) {
                    config.list.find(config.listSel).removeClass().eq(i).addClass(config.selClass);
                    index = Math.floor(i / config.listNum);
                    flip();
                }
            },
            msgrun = function () {
                (config.message !== null && config.message !== undefined) && config.message.eq(i).show().siblings().hide();
            },
            tab = function () {
                config.tabSel != null && $container.find(config.tabSel).eq(i).addClass(config.tabClass).siblings().removeClass(config.tabClass);
            },
            s = config.interval && setInterval(function () { call[config.type](config.direction); }, config.interval);
            tab();
            config.type == "slide" && $imgs.css("float") === "none" && $imgs.hide().eq(i).show().css("margin-left", 0).end().eq(i + 1).css("margin-left", width).end().eq(i - 1).css("margin-left", -width);
            config.type == "focus" && $imgs.hide().eq(0).show();
            $container//.add(config.leftBtn).add(config.rightBtn).add(config.list).add(config.prevBtn).add(config.nextBtn)
                    .hover(function () { clearInterval(s); }, function () { s = config.interval && setInterval(function () { call[config.type](config.direction); }, config.interval); });
            config.leftBtn != null && config.leftBtn.click(function () {
                if ($(":animated", $container).length === 0) call[config.type](false);
            });
            config.rightBtn != null && config.rightBtn.click(function () {
                if ($(":animated", $container).length === 0) call[config.type](true);
            });
            config.prevBtn != null && config.prevBtn.click(function () {
                if ($(":animated", $container).length === 0) { index = index == 0 ? 0 : index - 1; flip(); }
            });
            config.nextBtn != null && config.nextBtn.click(function () {
                if ($(":animated", $container).length === 0) { index = index == listPage - 1 ? listPage - 1 : index + 1; flip(); }
            });
            config.list != null && config.list.find(config.listSel).click(function () {
                $(":animated", $container).stop(false, true); var k = $(this).index(); /*if (k == i) return;*/call[config.type](k <= i, k);
            });
            config.tabSel != null && $container.find(config.tabSel).bind(config.tabEvent, function () {
                if (($(":animated", $container).length === 0 || config.type === "focus") && i !== $(this).index()) call[config.type](false, $(this).index());
            });
        },
        /////鼠标移动到图片上显示大图
        jbigimg: function (con) {
            var $img = $(this),
            option = {
                effect: "fadeIn"
            },
            config = $.extend(option, con),
            bi = $("<div id='bigimg' style='display:none; position:absolute; padding:5px; background-color:#fff; top:0px; left:0px; border:1px solid #ccc; z-index:1950;'><img /></div>").appendTo("body"),
            bii = $("img", bi);
            $(this).hover(function (e) {
                var _this = $(this);
                h_s = setTimeout(function () {
                    bii.attr("src", _this.attr("src"));
                    var _top = _this.offset().top, _left = _this.offset().left;
                    if (_top < $(window).scrollTop() + 40) _left > $(window).width() / 2 ? bi.fadeIn("fast").offset({ top: _top + _this.height() + 5, left: _left - bi.width() + _this.width() - 18 }) : bi.fadeIn("fast").offset({ top: _top + _this.height() + 5, left: _left });
                    else if (_top + _this.height() > $(window).scrollTop() + $(window).height() * 3 / 5) _left > $(window).width() / 2 ? bi.fadeIn("fast").offset({ top: _top - bi.height() - 18, left: _left - bi.width() + _this.width() - 18 }) : bi.fadeIn("fast").offset({ top: _top - bi.height() - 18, left: _left });
                    else if (_left > $(window).width() / 2) bi.fadeIn("fast").offset({ top: _top, left: _left - bi.width() - 18 });
                    else _left + _this.width() + bi.width() < $(window).width() ? bi.fadeIn("fast").offset({ top: _top, left: _left + _this.width() }) : bi.fadeIn("fast").offset({ top: _top + _this.height() + 5, left: _left });
                }, 500);
            }, function () {
                clearTimeout(h_s);
                bi.is(":visible") && bi.fadeOut("fast");
            });
        },
        /////弹出窗(点击窗口以外区域或者按ESC键关闭窗口,没有关闭按钮)
        jbox_close: function () {
            $("[id*='jbox-']").remove();
        },
        /////
        jbox: function (con, nowt, fun) {//nowt参数设置成true即调用jbox就触发打开窗口的事件,且只触发一次
            option = {
                locked: false, //背景锁定
                width: 800, //窗口宽度
                height: 600, //窗口高度
                opacity: 0.4, //背景透明度
                url: "", //请求url
                border: 15, //边框宽度
                effect: "height-width", //窗口进入的效果
                s_effect: "fadeIn", //背景出现效果
                para: "data-inbox", //调用的属性(调用div或者url)
                closebtn: true, //是否需要关闭按钮
                adaptive: false, //开启自适应高,如果内部元素没有设置高则以上面的参数为准
                top: 10, //开启自适应高之后开放的参数,自定义窗口的顶端
                icss: {}, //可以在最内部的窗口自定义CSS属性
                paracut: ""//删除属性里的字符串
            };
            return this.each(function () {
                var w = $(window).resize(function () {
                    ww = $(this).width(),
                    wh = $(this).height(),
                    l = (ww - $("#jbox-content").width()) / 2,
                    t = (wh - $("#jbox-content").height()) / 2;
                    $("#jbox-content").css({ top: t, left: l });
                    $("#jbox-border").css({ top: t - config.border, left: l - config.border });
                }),
                config = $.extend(option, con),
                tri = (typeof (con) === "boolean" && con) || nowt ? "openbox" : "click",
                loadContent = function (_this, ic) {
                    if (_this.attr(config.para) != undefined) {
                        if ($(_this.attr(config.para).replace(config.paracut, "")).length != 0) {
                            $(_this.attr(config.para).replace(config.paracut, "")).clone(true).prependTo(ic);
                            typeof (con) === "function" ? con() : (typeof (nowt) === "function" ? nowt() : (fun && fun()));
                        }
                        else if (_this.attr(config.para).replace(config.paracut, "").split(':')[0] == "img") {
                            $("<img />").attr("src", _this.attr(config.para).replace(config.paracut, "").split(':')[1]).prependTo(c);
                            typeof (con) === "function" ? con() : (typeof (nowt) === "function" ? nowt() : (fun && fun()));
                        }
                        else {
                            $.ajax({
                                url: _this.attr(config.para).replace(config.paracut, ""),
                                success: function (d) {
                                    ic.html($.trim(d));
                                    typeof (con) === "function" ? con() : (typeof (nowt) === "function" ? nowt() : (fun && fun()));
                                }
                            });
                        }
                    }
                    else if (config.url && config.url != "") {
                        $.ajax({
                            url: config.url,
                            success: function (d) {
                                ic.html($.trim(d));
                                typeof (con) === "function" ? con() : (typeof (nowt) === "function" ? nowt() : (fun && fun()));
                            }
                        });
                    }
                };
                $(this).bind(tri, function () {
                    _this = $(this),
                    ww = w.width(), wh = w.height(), l = (ww - config.width) / 2, t = (wh - config.height) / 2;
                    if ($(_this.attr(config.para).replace(config.paracut, "")).length != 0 && config.adaptive) {
                        var _i = $(_this.attr(config.para).replace(config.paracut, ""));
                        config.width = _i.width() != 0 ? _i.width() : config.width;
                        config.height = _i.height() != 0 ? _i.height() : config.height;
                    }
                    if (config.adaptive) { config.height = "auto"; t = config.top + 15; }
                    w.one("keyup", function (e) {
                        e = e || window.event;
                        e.keyCode == 27 && c.add(ic).add(s).add(b).remove();
                    }),
                    s = $("<div id='jbox-shadow'><div>").appendTo("body").css({
                        opacity: config.opacity
                    }).one("click", function () {
                        !config.locked && c.add(ic).add(s).add(b).remove(), this.onselectstart = function () { return false; };
                    }),
                    b = $("<div id='jbox-border'></div>").appendTo("body").css({
                        padding: config.border,
                        top: t - config.border,
                        left: l - config.border,
                        height: config.height + 20,
                        width: config.width + 40
                    }).hide(),
                    c = $("<div id='jbox-content'></div>").appendTo(b).css({}),
                    ic = $("<div id='jbox-incontent'></div>").appendTo(c).css({
                        height: config.height,
                        width: config.width
                    }).css(config.icss),
                    btnc = config.closebtn && $("<div class='jbox-close'></div>").appendTo(c).css({
                        right: -10
                    }).click(function () { c.add(ic).add(s).add(b).remove() }).hide();
                    $.fn.isCss3() && btnc.removeClass("jbox-close").addClass("jbox-close-css3");
                    if (config.effect != "" && config.effect != null && !config.adaptive) {
                        b.show();
                        if (config.effect.indexOf("bottom") >= 0) b.css("top", 1000);
                        else if (config.effect.indexOf("top") >= 0) b.css("top", -1000);
                        if (config.effect.indexOf("left") >= 0) b.css("left", -1000);
                        else if (config.effect.indexOf("right") >= 0) b.css("left", 1000);
                        if (config.effect.indexOf("height") >= 0) b.css({ "top": t + config.height / 2, "height": 0 }), c.hide();
                        if (config.effect.indexOf("width") >= 0) b.css({ "left": l + config.width / 2, "width": 0 }), c.hide();
                        b.animate({ left: l - config.border, top: t - config.border, height: config.height + 20, width: config.width + 40 }, function () { c.add(btnc).show(); loadContent(_this, ic); });
                    }
                    else {
                        b.fadeIn(function () { btnc.show(); });
                        loadContent(_this, ic);
                        if (b.height() + config.border * 2 + config.top > w.height()) {
                            ic.height(w.height() - (config.top + 10 + config.border) * 2);
                        }
                    }
                    if (config.s_effect != "" && config.s_effect != null) {
                        s.hide()[config.s_effect]();
                    }
                });
                if ((typeof (con) === "boolean" && con) || nowt) { $(this).trigger("openbox").unbind("openbox"); }
            });
        },
        /////抖动
        jshake: function (con, fun) {
            var _this = this,
				option = {
				    freq: 5, //抖动次数
				    margin: 5, //抖动幅度
				    prop: "right", //抖动位移使用的属性(如果做的更好的话可以没有这个参数)
				    speed: 300//抖动速度(总时间)
				},
				config = $.extend(option, con),
				i = 0,
				initial = Number(_this.css(config.prop).replace("px", ""));
            config.speed = config.speed / config.freq;
            function recursion(i, obj) {
                i++
                var f = i % 2 == 1 ? config.margin : -config.margin,
					animate;
                switch (config.prop) {
                    case "right": animate = { "right": initial + f }; break;
                    case "margin-right": animate = { "margin-right": initial + f }; break;
                    case "left": animate = { "left": initial + f }; break;
                    case "margin-left": animate = { "margin-left": initial + f }; break;
                    default: animate = null;
                };
                obj.stop().animate(animate, config.speed,
					function () {
					    if (i > config.freq) {
					        animate[config.prop] = initial;
					        obj.animate(animate, config.speed, function () { typeof (con) === "function" ? con() : fun && fun() });
					        return;
					    }
					    recursion(i, obj)
					});
            }
            if (!_this.is(":animated"))
                recursion(i, _this);
            return _this;
        },
        /////
        jbrowse: function (set) {
            !$.fn.isInclude("jPackage.css") && $("<link>").attr({ rel: "stylesheet", type: "text/css", href: "jPackageCss/jPackage.css" }).appendTo("head");
            var magnifier = $.fn.isInclude("jquery.mousewheel.js"), //拥有这个JS可以实现滚轮放大图片
				option = {
				    speed: 300, //图片展出/退出的速度
				    width: 150, //预览图宽度
				    height: "auto", //预览图高度(不设置保持原图比例)
				    size: 5, //同时显示预览图的个数
				    border: true//true:外框根据图片改变大小|false:外框满屏
				};
            return this.each(function () {
                var config = $.extend(option, set),
						_this = $(this).css({ "overflow": "hidden" }),
						_ul = $("ul", _this).height(180).wrap("<div class='jbrowse-content'></div>"),
						_div = _ul.parent("div").width((config.width + 40) * config.size),
						_back = $("<div class='jbrowse-back'></div>").prependTo(_this),
						_forward = $("<div class='jbrowse-forward'></div>").appendTo(_this),
						_li = $("li", _this).width(config.width),
						_background = $("<div class='jbrowse-background'></div>").css({ "opacity": 0.5 }).appendTo(_this),
						_container = $("<div class='jbrowse-container'></div>").appendTo(_this),
						_tempimg = $("<img class='jbrowse-tempimg' />").appendTo(_this),
						_img = $("<img class='jbrowse-img' />").appendTo(_container).wrap("<div class='jbrowse-warp'></div>"),
						_wrap = _img.parent(),
						_move = $("<div class='jbrowse-move'></div>").appendTo(_wrap),
						_prev = $("<div class='jbrowse-prev'></div>").prependTo(_container),
						_next = $("<div class='jbrowse-next'></div>").appendTo(_container),
						_len = _li.length,
						_hide = true,
						_info = null;
                _this[0].ondragstart = function () { return false; }
                _ul.width((config.width + 40) * _len);
                !config.border && _img.css({ "margin-top": ($(window).height() - 30) / 2, "margin-left": ($(window).width() - 100) / 2 });
                $("img", _li).css({ width: config.width, height: config.height });
                if ($.browser.msie && parseInt($.browser.version) === 8 && config.height != 180)//IE8下图片居中
                    _li.each(function () {
                        $("img", this).css({ "margin-top": (180 - $("img", this).height()) / 2 });
                    })
                var _page = 0;
                _back.click(function () {
                    _page = _page > 0 ? _page - 1 : (_len - config.size < 0 ? 0 : _len - config.size);
                    _ul.stop(true, false).animate({ "margin-left": -(config.width + 40) * _page });
                })
                _forward.click(function () {
                    _page = _page < _len - config.size ? _page + 1 : 0;
                    _ul.stop(true, false).animate({ "margin-left": -(config.width + 40) * _page });
                })
                var _index = 0;
                _prev.click(function () {
                    if (_index > 0) _index--;
                    else { _index = 0; return; }
                    showimg();
                })
                _next.click(function () {
                    if (_index < _len - 1) _index++;
                    else { _index = _len - 1; return; }
                    showimg();
                })
                _li.click(function () {
                    _index = $(this).index();
                    showimg();
                })
                var proportion = 1, //图片缩放比例
					_proportion = 1, //图片打开时的比例
					top, left,
					size; //元始大小
                var showimg = function () {
                    _hide = false;
                    _tempimg.height("auto");
                    _img.add(_tempimg).attr("src", $("img", _li.eq(_index)).attr("src")).css({ "margin": 0 });
                    size = { width: _tempimg.width(), height: _tempimg.height() };
                    _tempimg.height() >= $(window).height() - 50 ? _tempimg.height($(window).height() - 50) : _tempimg.height("");
                    var wh = { width: _tempimg.width(), height: _tempimg.height() };
                    top = ($(window).height() - wh.height) / 2 - 10;
                    left = ($(window).width() - wh.width) / 2 - 10;
                    proportion = _proportion = wh.width / size.width;
                    if (config.border) {
                        if (_container.is(":hidden"))
                            _container.add(_background).show().css({ top: $(window).height() / 2, left: $(window).width() / 2 });
                        _container.add(_img).add(_background).add(_wrap).stop(true, false).animate({
                            top: top,
                            left: left,
                            width: wh.width,
                            height: wh.height
                        }, config.speed, function () {
                            _container.attr("vis", "true");
                            _next.add(_prev).show().css({ top: (wh.height - 35) / 2 });
                            _move.show();
                            setTimeout(function () { _hide = true; }, 500); //_hide防止图片变小时仍在外面点击关闭图片
                            _info = _info == undefined && $("<div class='jbrowse-p-info'><span></span>%</div>").appendTo(_wrap).css({ top: wh.height / 2, left: wh.width / 2 })
                        });
                        _next.add(_prev).hide();
                        _move.css({ top: 0, width: wh.width, height: wh.height + 20, "opacity": 0 }).hide();
                    }
                    else if (!config.border) {
                        if (_container.is(":hidden"))
                            _container.add(_background).show().css({ top: 0, left: 0, width: $(window).width() - 100, height: $(window).height() - 30 });
                        _img.stop(true, false).css({
                            "margin-top": ($(window).height() - wh.height) / 2 - 10,
                            "margin-left": ($(window).width() - wh.width) / 2 - 10,
                            width: wh.width,
                            height: wh.height
                        }, config.speed, function () {
                            _container.attr("vis", "true");
                            setTimeout(function () { _hide = true; }, 500); //_hide防止图片变小时仍在外面点击关闭图片
                            _info = _info == undefined && $("<div class='jbrowse-p-info'><span></span>%</div>").appendTo(_wrap).css({ top: wh.height / 2 - 15, left: wh.width / 2 - 35 })
                        });
                        _next.add(_prev).stop(true, false).animate({ top: ($(window).height() - 65) / 2 });
                        _move.css({ top: 0, width: $(window).width() - 100, height: $(window).height(), "opacity": 0, "margin": "auto" })
                    }
                }
                if (config.border) {
                    $(document).click(function (e) {
                        if (_this.find(e.target).length != 0) return false;
                        if (_container.attr("vis") == "true" && _hide) {
                            _container.add(_img).add(_background).animate({
                                top: $(window).height() / 2 - 10,
                                left: $(window).width() / 2 - 10,
                                width: 0,
                                height: 0
                            }, config.speed, function () {
                                _container.attr("vis", "false").hide(); _background.hide();
                            });
                        }
                    });
                }
                else if (!config.border) {
                    $(document).keyup(function (e) {
                        e = e || window.event;
                        e.keyCode == 27 && _background.add(_container).hide();
                    });
                }
                if (magnifier) {//可缩放
                    var do_move = false,
						wmousewheel = true,
						_run = true,
						mouse = { x: 0, y: 0 },
						imgP = { x: 0, y: 0 },
						_timer = null;
                    _move.bind("mousewheel", function (event, delta) {
                        _zoom(event, delta);
                    }).dblclick(function () {
                        _zoom(event, 1);
                    }).mousedown(function (e) {
                        do_move = true;
                        e = e || window.event;
                        mouse = { x: e.clientX, y: e.clientY },
							imgP = { x: Number(_img.css("margin-left").replace("px", "")), y: Number(_img.css("margin-top").replace("px", "")) };
                    }).mousemove(function (e) {
                        if (!do_move) return;
                        e = e || window.event;
                        _img.css({ "margin-left": imgP.x + (e.clientX - mouse.x), "margin-top": imgP.y + (e.clientY - mouse.y) });
                    }).mouseover(function () {
                        wmousewheel = false;
                        window.onmousewheel = function () { if (!wmousewheel) return false; } //鼠标在图片区域内禁止页面默认滚轮事件
                    }).mouseup(function () {
                        do_move = false;
                    }).mouseout(function () {
                        do_move = false;
                        wmousewheel = true;
                    });
                    var _zoom = function (event, delta) {
                        if (_run) {
                            event = event || window.event;
                            _run = false;
                            imgP = { x: event.clientX - _wrap.offset().left, y: event.clientY - _wrap.offset().top }
                            ml = (imgP.x - Number(_img.css("margin-left") == "auto" ? 0 : _img.css("margin-left").replace("px", ""))) / proportion;
                            mt = (imgP.y - Number(_img.css("margin-top") == "auto" ? 0 : _img.css("margin-top").replace("px", ""))) / proportion;
                            $("span", _info).text((proportion * 100).toString().split(".")[0]).parent().fadeIn();
                            proportion = proportion + delta * proportion * 0.5;
                            ml = -(ml * proportion - imgP.x);
                            mt = -(mt * proportion - imgP.y);
                            if (_timer != null) clearTimeout(_timer);
                            _img.animate({ width: size.width * proportion, height: size.height * proportion, "margin-left": ml, "margin-top": mt }, 500, function () {
                                _run = true;
                                _timer = setTimeout(function () { _info.fadeOut(); }, 1000);
                                clearInterval(_interval);
                                $("span", _info).text((proportion * 100).toString().split(".")[0])
                            });
                            proportion > 1 && $("span", _info).text(Number((proportion * 100).toString().split(".")[0]) - 50 * delta);
                            var _interval = setInterval(function () {
                                $("span", _info).text(Number($("span", _info).text()) + delta);
                                if (Number((proportion * 100).toString().split(".")[0]) == Number($("span", _info).text())) clearInterval(_interval);
                            }, 10);
                        }
                    }
                }
            });
        },
        jselect: function (set, change) {
            option = {
                options: [["0", "请选择"]], //[["0", "请选择"]] 或者 ["","",""] 格式
                selected: 0,
                name: ""
            };
            $(document).click(function (e) { !$(e.target).add($(e.target).parents()).hasClass("jselect-main") && $(".jselect-list").hide(); })
            return this.each(function () {
                var config = $.extend(option, set),
                _this = $(this).empty(),
                _q = $("<q></q>").appendTo(_this),
                _input = $("<input type='hidden' />").appendTo(_this).attr("name", config.name),
                _triangle = $("<div class='jselect-triangle'><div class='fontello'>&#xe840;</div></div>").appendTo(_this),
                _list = $("<div class='jselect-list'></div>").appendTo(_this),
                _inlist = [];

                _this.addClass("jselect-main");

                if (typeof (config.options[0]) == "string") {
                    _inlist[_inlist.length] = "<ul>";
                    for (var i = 0; i < config.options.length; i++) {
                        _inlist[_inlist.length] = "<li value='" + i + "'>" + config.options[i] + "</li>";
                    }
                    _inlist[_inlist.length] = "</ul>";
                    _list.html(_inlist.join(""));
                    if (typeof (config.selected) != "boolean" || config.selected) {
                        _q.text(config.options[config.selected]).attr("value", config.selected);
                        _input.val(config.selected)
                    }
                }
                else {
                    _inlist[_inlist.length] = "<ul>";
                    for (var i = 0; i < config.options.length; i++) {
                        _inlist[_inlist.length] = "<li value='" + config.options[i][0] + "'>" + config.options[i][1] + "</li>";
                    }
                    _inlist[_inlist.length] = "</ul>";
                    _list.html(_inlist.join(""));
                    if (typeof (config.selected) != "boolean" || config.selected) {
                        _q.text(config.options[config.selected][1]).attr("value", config.options[config.selected][0])
                    }
                }

                if (config.options.length > 10)
                    _list.css({ "max-height": $("li", _this).height() * 10, "overflow-y": "scroll" });

                _this.unbind("click").click(function () { _f(); });

                var _f = function () {
                    var _s = $(".jselect-list", _this);
                    $(".jselect-list").not(_s).hide();
                    _s.is(":hidden") ? _s.show() : _s.hide();
                }

                $("ul li", _list).click(function () {
                    var __this = $(this),
                    _old = _q.attr("value"),
                    _new = __this.attr("value");
                    if (_old != _new) {
                        _q.text(__this.text()).attr("value", _new);
                        _input.val(_new)
                        typeof (change) === "function" && change(__this.attr("value"));
                    }
                })
            });
        },
        jnumroll: function (set) {
            return this.each(function () {
                if (typeof (set) == "number") {
                    if ($(".jnum-behidden", this).length == 0) {
                        _value = set.toString().split("");
                        var new_value = [];
                        for (var i = 0; i < $("dl:not(.jnum-split)", this).length - _value.length; i++) {
                            new_value[i] = "0";
                        }
                        for (var i = 0; i < _value.length; i++) {
                            new_value[new_value.length] = _value[i];
                        }

                        $("dl", this).not(".jnum-split").each(function (i) {
                            $(this).animate({ "top": -Number(new_value[i]) * _height });
                        });
                    }
                }
                else {
                    option = {
                        type: 1, //1:直接滚动到目标数字|2:不停翻滚,从个位开始停止
                        split: true, //是否需要千位分隔符
                        before: "", //数字前面的标识符,如"$"或者"￥"
                        end: "" //数字末尾的单位,如"元"
                    };
                    var config = $.extend(option, set), _this = $(this), _width = _this.width(), _value = _this.text().split(""), _len = _value.length, _one_width = _width / _len;
                    _height = _this.height();
                    if (_value[0] == "0") config.split = false;
                    var _numcon = $("<div class='jnum-main' />").appendTo(_this.empty().html("&nbsp;")).css({ "height": _height, "line-height": _height + "px" });
                    _numcon.css({ "top": _this.offset().top - _numcon.offset().top });
                    var _delimiter = _len % 3, _inner = [];
                    if (config.before != "") {
                        _inner[_inner.length] = "<dl class='jnum-split'>" + config.before + "</dl>";
                    }
                    for (var i = 0; i < _len; i++) {
                        _inner[_inner.length] = "<dl style='width:" + _one_width + "px;'>";
                        if (config.type == 2) { _inner[_inner.length] = "<dd class='jnum-behidden'>9</dd>"; }
                        for (var j = 0; j < 10; j++) {
                            _inner[_inner.length] = "<dd>" + j + "</dd>";
                        }
                        _inner[_inner.length] = "</dl>";
                        if (config.split && (i + 1) % 3 == _delimiter && i != _len - 1) { _inner[_inner.length] = "<dl class='jnum-split' style='width:" + _one_width + "px;'>,</dl>"; }
                    }
                    if (config.end != "") { _inner[_inner.length] = "<dl class='jnum-split'>" + config.end + "</dl>"; }
                    _numcon.html(_inner.join(""))

                    var __width = 0;
                    $("dl", _numcon).each(function () {
                        __width = __width + $(this).css({ "left": __width }).width();
                    })
                    _numcon.width(__width)

                    var stop = _value.length - 1;
                    if (config.type == 1) {
                        $("dl", _numcon).not(".jnum-split").css({ "top": -(_height * 9) }).each(function (i) {
                            $(this).animate({ "top": -Number(_value[i]) * _height });
                        });
                    }
                    else if (config.type == 2) {
                        zero = true;
                        $("dl", _numcon).not(".jnum-split").css({ "top": -(_height * 10) }).each(function (i) {
                            if (_value[i] != "0") {
                                zero = false;
                            }
                            else if (_value[i] == "0" && zero) {
                                $(this).animate({ "top": -Number(_value[i]) * _height }).find(".jnum-behidden").remove();
                            }
                            if (!zero) {
                                var _top = -(_height * 10), _obj = this, _b_value = _value;
                                _obj.interval = setInterval(function () {
                                    if (_top == 0) { _top = -(_height * 10); }
                                    $(_obj).css({ "top": _top++ });
                                    if (i == stop && _top == -Number(_b_value[i]) * _height) {
                                        stop--;
                                        $(_obj).css({ "top": _top }).find(".jnum-behidden").remove();
                                        clearInterval(_obj.interval);
                                        return false;
                                    }
                                }, 1)
                            }
                        });
                    }
                }
            });
        }
    });
    setTimeout(function () {//jtips
        var tips_timer = null;
        $("*[data-title]").hover(function (e) {
            var _this = $(this);
            tips_timer = setTimeout(function () {
                $("<div id='jtips-main'></div>").html(_this.attr("data-title")).appendTo("body").fadeIn().css({
                    top: e.clientY + 10,
                    left: e.clientX + 10
                });
            }, 300)
        }, function () {
            clearTimeout(tips_timer);
            $("#jtips-main").fadeOut(function () { $(this).remove(); });
        })
    }, 500)
})(jQuery);